<include file="public@storage"/>
</head>
<body>
<div class="container body-content" style="margin-top:20px;width: 100%">
    <div class="panel panel-info" style="margin-bottom: 0.5rem">
        <div class="panel-heading">客户端管理</div>
        <div class="panel-body">
            <div class="row">
                <div class="col-sm-12">
                    <div id="toolbar" class="btn-group">
                        <button id="addUser" class="btn btn-info" style="margin-left: 1rem; width: 10rem"
                                onclick="addClient()">添加客户端
                        </button>
                    </div>
                    <table id="table"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    $(function () {
        init();
    });

    function init() {
        var url = "{:url('storage/Client/getClient')}";
        var columns = [
            {
                title: '序号',
                width: 50,
                align: "center",
                valign: "middle",
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },
            {
                title: 'id',
                field: 'id',
                visible: false
            },
            {
                title: '编码',
                field: 'code',
                align: "center"
            },
            {
                title: '名字',
                field: 'name',
                align: "center"
            },
            {
                title: '所属仓库',
                field: 'storage_name',
                align: "center"
            },
            {
                title: '标注',
                field: 'remark',
                align: "center"
            },
            {
                title: '是否在线',
                field: 'is_online',
                align: "center",
                formatter: function (value) {
                    if (value === 1) {
                        return '在线';
                    } else {
                        return '<span style="color:red;font-weight: bolder">' + '离线' + '</span>';
                    }
                }
            },
            {
                title: '状态',
                field: 'status',
                align: "center",
                formatter: function (value) {
                    if (value === 1) {
                        return '正常';
                    } else {
                        return '<span style="color:red;font-weight: bolder">' + '异常' + '</span>';
                    }
                }
            },
            {
                title: '操作',
                field: 'uuid',
                align: "center",
                valign: "middle",
                formatter: function (value, row, index) {
                    html = '<a onclick="editClient(this)" href="javascript:void(0);" data-id="' + row.id + '">编辑</a>';
                    html += '&ensp;|&ensp;';
                    html += '<a onclick="deleteClient(this)" href="javascript:void(0);" data-id="' + row.id + '" data-code="' + row.code + '">删除</a>';
                    return html;
                }
            }
        ];
        initTable(url, columns, 'client',false,true);
    }

    function addClient() {
        window.open('/storage/Client/add', '_self');
    }

   deleteClient = function (that) {
        var id = $(that).data('id');
        var code = $(that).data('code');
        var data = {
           id: id
        };
        var tip = '是否删除编码' + code;
        var url = "{:url('/storage/Client/deleteClient')}";
        reviseTable(tip, url, data);

    };

    editClient = function (that) {
        var id = $(that).data('id');
        window.open('/storage/Client/edit?id=' + id, '_self');
    };
</script>
</html>